package ControleAcamico;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;


import ControleDiversas.AdicionarTurmaJBDC;
import ControleDiversas.MetodoCursoDAO;
import ControleDiversas.MetodoDePesquisaCPA;
import ControleDiversas.PesquisarTurma;
import ControleDiversas.ProfessorDao;
import ModeloAcademico.ModelCurso;
import ModeloAcademico.ModeloMatricula;
import ModeloAcademico.ModeloTurma;
import VisaoControleAcademico.MatriculaView;
import VisaoControleAcademico.NovaTurma;
import VisaoControleAcademico.PainelListaAluno;
import VisaoControleAcademico.PainelPrincipal;
import VisaoControleAcademico.ViewCurso;
import VisaoControleAcademico.Visao;

public class ControlePrincipal implements ActionListener {
	private Visao visao;
	private MatriculaView matV;
	private ViewCurso visaoCurso;  
	public void iniciarTelaPrincipal() {
		visao = new PainelPrincipal(this);
		visao.mostra();
	}
	public void mostrarCurso() {
		visaoCurso = new ViewCurso(this);
		visaoCurso.mostra();
	}

	private void edicaoMAtricula() {
		matV = new MatriculaView(this);
		matV.mostrarMatricula();
	}

	private void edicaoAluno() {
		PainelListaAluno addL = new PainelListaAluno(this);
		addL.mostrarListaAlunos();
	}

	private void edicaoNovaTurma() {
		NovaTurma addL = new NovaTurma(this);
		addL.mostrarNovaMatricular();
	}

	public void actionPerformed(ActionEvent e) {

		// //////Menu
		
		/*if (e.getActionCommand().equals("Curso")) {// cadastro
			PainelPrincipal.InternalFrameCurso();
		}*/
		if (e.getActionCommand().equals("Professor")) {// cadastro
			ControleDeProfessor d= new  ControleDeProfessor();
			d.edicao();
			ProfessorDao.pesquisa();
		}
		if (e.getActionCommand().equals("Aluno")) {// cadastro
			ControleDiversas.AlunoControlador d = new ControleDiversas.AlunoControlador();
			d.edicao();
		}
		/*if (e.getActionCommand().equals("Turma")) {// cadastro
			PainelPrincipal.InternalFrameTurma();
			PesquisarTurma.adicionarJListTurma();
		}*/

		if (e.getActionCommand().equals("Realizar")) {// Matricula
			edicaoMAtricula();
		}
		if (e.getActionCommand().equals("Registrar Aulas")) {// Matricula
			RegistroAulasControlador d = new RegistroAulasControlador();
			d.edicao2();
		}
		// ////////////////////

		// Curso Interna
		if (e.getActionCommand().equals("Cadastrar Curso")) {
			mostrarCurso();

		}
		// Curso Interna
		if (e.getActionCommand().equals("Pesquisar Curso")) {
			MetodoCursoDAO.pesquisaCurso();
		}
		
		if(e.getActionCommand().equals("Alterar Curso")){
			JOptionPane.showMessageDialog(null, "Teste");
			MetodoCursoDAO.alteraCurso();
			if (PainelPrincipal.tabResultPesqCurso.getSelectedRow() >=0 ) {
				MetodoCursoDAO.RemoverPessoa();
			}
		}

		// Curso Externa
		if (e.getActionCommand().equals("Cadastrar_Curso")) {
			ControleCurso.execucao(new ModelCurso(
					ViewCurso.NomeCurso.getText(), ViewCurso.cronograAulas
							.getText(), ViewCurso.QntdHoras.getText(),
					ViewCurso.Valor.getText()));
			ViewCurso.metodoLimparCampoCurso();
		}
		// Curso Externa
		if (e.getActionCommand().equals("Limpar Campos")) {
			ViewCurso.metodoLimparCampoCurso();
		}		
		// ///////////Turma
		if (e.getActionCommand().equals("Nova Turma")) {// nova turma
			edicaoNovaTurma();
			MetodoDePesquisaCPA.pesquisarNovaTurma();
		}
		if (e.getActionCommand().equals("Cadastrar Turma")) {
			String valor1 = NovaTurma.textNome.getText();
			String valor2 = (String) NovaTurma.jcCurso.getSelectedItem();
			String valor3 = NovaTurma.textDiasAula.getText();
			ControleTurma.MetodoTurmas(new ModeloTurma(valor1, valor2, valor3));

		}
		if (e.getActionCommand().equals("Pesquisar")) {// pesquisar turma
		    new	PesquisarTurma();
		    PainelPrincipal.metodoLimparCampo();
		}
		if (e.getSource() == NovaTurma.jcCurso) {
			MetodoDePesquisaCPA.nadoJcomBomboxTurma();
		}

		if (e.getSource() == PainelPrincipal.alterarTurma) {// /alterar turma
			String g = PainelPrincipal.textPesquisaTurma.getText();
			try {
				ClalseAlterarTurma.altera();//Neste metodo esta o de adicionar
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}

		// //Mtricula
		if (e.getActionCommand().equals("Selecionar Alunos")) {// Matricula
			edicaoAluno();
		}

		if (e.getActionCommand().equals("Excluir Aluno")) {// matricula
			MatriculaView.removeAluno();
		}

		if (e.getActionCommand().equals("Cadastrar")) {
			String v1 = (String) MatriculaView.jcomTurmaMatri.getSelectedItem();
			String v2 = (String) MatriculaView.jcomCursoMatri.getSelectedItem();
			String v3 = MatriculaView.txtDataMatri.getText();
			String tal = MatriculaView.areaMatriCont.getText();
			for (int i = 0; i < MatriculaView.tabelaMatri.getRowCount(); i++) {
				String altenome1 = MatriculaView.tabelaMatri.getValueAt(i, 0)
						.toString();
				ContrlMatricula.MatricularTurma(new ModeloMatricula(v1, v2, v3,
						tal, altenome1));
			}
			
		}
		
		if (e.getSource() == MatriculaView.jcomCursoMatri) {
			MetodoDePesquisaCPA.atualizarJcombomboxMatricula();
			
		}

	}

}
